package avicit.bdp.dms.prm.rest;

import avicit.bdp.common.utils.ConfigUtils;
import avicit.bdp.dms.prm.service.ConfigService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2021-09-27
 * @类说明：LoginPermRest
 * @修改记录：
 * @注意事项：
 * @主要功能：用户登录页面图片通用设置Rest接口
 */

@RestController
@Api(tags = "登录页统一配置接口")
@RequestMapping("/api/bdp/dms/prm/loginRes")
public class LoginResRest {

    @Autowired
    private ConfigService configService;

    @ApiOperation(value = "新增/编辑配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "systemName", value = "系统名称", dataType = "String"),
            @ApiImplicitParam(name = "loginLogo", value = "登录logo", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "loginbg", value = "登录背景图", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "copyright", value = "版权说明", dataType = "String"),
            @ApiImplicitParam(name = "copyrightIsShow", value = "是否显示", dataType = "Boolean"),
            @ApiImplicitParam(name = "indexLogo", value = "首页logo", dataType = "String"),
            @ApiImplicitParam(name = "indexAddress", value = "首页地址", dataType = "String"),
            @ApiImplicitParam(name = "layout", value = "导航", dataType = "String"),
            @ApiImplicitParam(name = "skin", value = "皮肤", dataType = "String"),
            @ApiImplicitParam(name = "domain", value = "区域", dataType = "String")
    })
    @PostMapping("/saveLoginRes")
    public ResponseMsg<Boolean> saveLoginRes(String systemName, MultipartFile loginLogo,MultipartFile loginbg,
                                              String copyright, Boolean copyrightIsShow,
                                              MultipartFile indexLogo, String indexAddress, String layout,String skin
            ,String domain) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(configService.saveLoginRes(systemName,loginLogo,loginbg,copyright,copyrightIsShow
                ,indexLogo,indexAddress,layout,skin,domain));
        return responseMsg;
    }

    @GetMapping("/getLoginRes")
    @ApiOperation(value = "查询登录页配置")
    public ResponseMsg<Map<String, String>> getLoginRes() {
        ResponseMsg<Map<String,String>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(ConfigUtils.getInstance().getMapByGroup("loginRes"));
        return responseMsg;
    }
}
